home *** CD-ROM | disk | FTP | other *** search
- #include <X11/Xlib.h>
- #define __TYPES
- #include <math.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include "hippo.h"
-
- static int width=600, height=600;
-
- static void doHandleEvents();
- int main()
- {
- ntuple *nt_list;
- display d_list[9];
- FILE *outfile;
- int nnt,i;
-
- /*
- * read in example ntuple
- */
- if (h_read("example.hippo",d_list,&nt_list) != 0)
- {
- fprintf(stderr,"Error reading file example.hippo\n");
- exit(1);
- }
-
- /*
- * check a few things
- */
- for (nnt=0; nt_list[nnt] != NULL; nnt++);
- if (nnt != 1)
- {
- fprintf(stderr,"There are %d ntuples in the file\n",nnt);
- fprintf(stderr," There should only be 1!\n");
- exit(1);
- }
-
- /*
- * create 9 displays
- */
-
- if ((d_list[0] = h_newDisp(HISTOGRAM)) == NULL)
- {
- fprintf(stderr,"Error creating display\n");
- exit(1);
- }
- if ((d_list[1] = h_newDisp(HISTOGRAM)) == NULL)
- {
- fprintf(stderr,"Error creating display\n");
- exit(1);
- }
- if ((d_list[2] = h_newDisp(HISTOGRAM)) == NULL)
- {
- fprintf(stderr,"Error creating display\n");
- exit(1);
- }
- if ((d_list[3] = h_newDisp(HISTOGRAM)) == NULL)
- {
- fprintf(stderr,"Error creating display\n");
- exit(1);
- }
- if ((d_list[4] = h_newDisp(HISTOGRAM)) == NULL)
- {
- fprintf(stderr,"Error creating display\n");
- exit(1);
- }
- if ((d_list[5] = h_newDisp(SCATTERPLOT)) == NULL)
- {
- fprintf(stderr,"Error creating display\n");
- exit(1);
- }
- if ((d_list[6] = h_newDisp(COLORPLOT)) == NULL)
- {
- fprintf(stderr,"Error creating display\n");
- exit(1);
- }
- if ((d_list[7] = h_newDisp(COLORPLOT)) == NULL)
- {
- fprintf(stderr,"Error creating display\n");
- exit(1);
- }
- if ((d_list[8] = h_newDisp(LEGOPLOT)) == NULL)
- {
- fprintf(stderr,"Error creating display\n");
- exit(1);
- }
-
- /*
- * set display attributes
- */
- for (i=0; i<9; i++)
- {
- h_bindNtuple( d_list[i], nt_list[0] );
- h_bind(d_list[i],XAXIS, 3);
- h_bind(d_list[i],YAXIS, 10);
- }
-
- h_setDrawType(d_list[1],ERRBAR);
- h_setDrawType(d_list[2],POINT+LINE);
- h_setDrawType(d_list[3],POINT+LINE);
- h_setPlotSym(d_list[3],TIMES);
- h_setLineStyle(d_list[3],DOTDASH);
- h_bind(d_list[3],WEIGHT,10);
-
- h_setDrawType(d_list[7],COLOR);
-
- h_setPlotDrvr(X11PLOT);
- /*
- * now create X output of display
- * we make one large window, then six sub-windows, one for each plot
- *
- */
-
- {
- Display *disp = XOpenDisplay(NULL);
- Screen *scrn = XDefaultScreenOfDisplay(disp);
- GC gc = DefaultGCOfScreen(scrn);
- XSetWindowAttributes xswa;
- Window main, wind[10];
-
- xswa.event_mask = ExposureMask | ButtonPressMask | StructureNotifyMask;
- xswa.background_pixel = WhitePixelOfScreen(scrn);
-
- main = XCreateWindow(disp,DefaultRootWindow(disp),
- 10,10,width,height,0,
- DefaultDepthOfScreen(scrn), InputOutput,
- DefaultVisualOfScreen(scrn),
- CWEventMask | CWBackPixel, &xswa);
-
- xswa.event_mask = ExposureMask | ButtonPressMask;
- for (i=0; i<9; i++)
- {
- wind[i] = XCreateWindow(disp,main,
- (i-i/3*3)*200,(i/3)*200,200,200,0,
- DefaultDepthOfScreen(scrn), InputOutput,
- DefaultVisualOfScreen(scrn),
- CWEventMask | CWBackPixel, &xswa);
- XMapWindow(disp,wind[i]);
- }
-
- XStoreName(disp, main, "X-Hippo example display");
- XMapWindow(disp,main);
- wind[9]=main;
- doHandleEvents(d_list,disp,scrn,wind,gc);
- }
-
- }
- static void doHandleEvents(display disp[],Display *dpy,Screen *scrn,Window wind[],GC gc)
- {
- XEvent event;
- XAnyEvent *any = (XAnyEvent *) &event;
- XExposeEvent *expose = (XExposeEvent *) &event;
- XConfigureEvent *config = (XConfigureEvent *) &event;
- int i;
-
- for ( ; ; ) {
- XNextEvent(dpy, &event);
-
- for (i=0; i<9; i++) if (any->window==wind[i]) break;
-
- switch (event.type) {
- case Expose: if (expose->count==0)
- {
- printf("expose %d\n",i);
- if (i<9)
- h_plot(disp[i],dpy,scrn,wind[i],gc);
- if (i==4)
- {
- h_shade(disp[i],0. ,40. );
- h_shade(disp[i],60.,100.);
- }
- }
- break;
- case ButtonPress: printf("Button press in window %d\n",i);
- break;
-
- case ConfigureNotify:
-
- if (config->width != width ||
- config->height != height)
- {
- int x,y,w,h;
-
- height = config->height;
- width = config->width;
-
- w = width/3;
- h = height/3;
- x = 0;
- y = 0;
-
- for (i=0; i<9; i++)
- {
- XMoveResizeWindow(dpy,wind[i],x,y,w,h);
- x += w;
- if (i == 2 || i == 5)
- { x = 0; y += h; }
- }
- }
- break;
- }
- }
- }
-